package superchat;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SuperChatFileSelector.java
 *
 * Created on 17 oct. 2011, 10:29:18
 */
/**
 * Classe pour la fenêtre de séléction de fichier
 * @author georgesm
 */
public class SuperChatFileSelector extends javax.swing.JDialog {

    /** Creates new form SuperChatFileSelector */
    public SuperChatFileSelector(java.awt.Frame parent, boolean modal, SuperChatView mainView, boolean selectMode, String message) {
        super(parent, modal);
        this.selectMode = selectMode;
        this.mainView = mainView;
        this.message = message;
        initComponents();
        if(selectMode) {
            jFileChooser1.setFileSelectionMode(jFileChooser1.FILES_ONLY);
        }
        else {
            jFileChooser1.setFileSelectionMode(jFileChooser1.DIRECTORIES_ONLY);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(500, 400));
        setName("Form"); // NOI18N

        jFileChooser1.setMinimumSize(new java.awt.Dimension(500, 400));
        jFileChooser1.setName("jFileChooser1"); // NOI18N
        jFileChooser1.setPreferredSize(new java.awt.Dimension(700, 500));
        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 460, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 290, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Action enclenchée lors de l'appuis sur "ok"
     * @param evt 
     */
    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed
        // TODO add your handling code here:
        if(selectMode) {
            mainView.requestFileSend(jFileChooser1.getSelectedFile().toString());
        }
        else {
            mainView.acceptFileTransfert(jFileChooser1.getSelectedFile().toString(), message);
        }
        this.setVisible(false);
    }//GEN-LAST:event_jFileChooser1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                SuperChatFileSelector dialog = new SuperChatFileSelector(new javax.swing.JFrame(), true, null, false, null);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    boolean selectMode;
    SuperChatView mainView;
    String message;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration//GEN-END:variables
}
